home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / JForth / Extras / ODE / obj_ivars < prev    next >
Encoding:
Text File  |  1991-10-24  |  2.7 KB  |  118 lines

  1. \ Optimized Instance Variables
  2. \ These are intended to make it easier to use instance variables.
  3. \ These IVARS will automatically fetch their data.  This can be optimized
  4. \ like crazy.  If you want to store into them, you use IV=> .
  5. \
  6. \ Author: Phil Burk
  7. \ Copyright 1986 Delta Research
  8. \
  9. \ MOD: PLB 5/13/87 Make iv&> immediate, use os+
  10. \ MOD: PLB 9/13/88 Convert to new addressing mode, add IV.BYTES
  11. \      Add signed ivars.
  12. \ MOD: PLB 2/7/90 Add IV.STRUCT
  13.  
  14. ANEW TASK-OBJ_IVARS
  15.  
  16. decimal
  17. \ Support for fetching and storing into instance variables .
  18. \ These should not be called directly.
  19.  
  20. \ Make JFORTH compile @ ! etc. inline for speed.
  21. #host_amiga_jforth .IF
  22. max-inline @ 20 max-inline !
  23. .THEN
  24.  
  25. false .IF
  26. : IV@  ( offset -- value , fetch from LONG instance variable )
  27.     os+ @
  28. ;
  29. : IVW@ ( offset -- value , fetch from SHORT instance variable )
  30.     os+ w@
  31. ;
  32. : IVC@ ( offset -- value , fetch from SHORT instance variable )
  33.     os+ c@
  34. ;
  35.  
  36. : IV!  ( value offset -- , store into LONG instance variable )
  37.     os+ !
  38. ;
  39. : IVW!  ( value offset -- , store into SHORT instance variable )
  40.     os+ w!
  41. ;
  42. : IVC!  ( value offset -- , store into BYTE instance variable )
  43.     os+ c!
  44. ;
  45. .THEN
  46.  
  47. : IV+!  ( value offset -- , store into LONG instance variable )
  48.     os+ +!
  49. ;
  50.  
  51. #host_amiga_jforth .IF
  52.     max-inline !
  53. .THEN
  54.  
  55. : CREATE.IVAR ( size <name> -- )
  56.     CREATE ob.make.member   immediate
  57.     DOES>  ( -- address-ivar )
  58.         ?comp compile os.copy
  59.         ob.stats compile+@bytes
  60. ;
  61.  
  62. \ These words are for declaring instance variables.
  63. \ Some of this code appears redundant but is needed because they
  64. \ are CREATE-DOES> words.
  65. : IV.LONG  ( <name> --IN-- , declare a cell wide instance variable )
  66.     4 create.ivar
  67. ;
  68.  
  69. : IV.SHORT  ( <name> --IN-- , declare a 16 bit wide instance variable )
  70.     -2 create.ivar
  71. ;
  72.  
  73. : IV.USHORT  ( <name> --IN-- , declare a 16 bit wide instance variable )
  74.     2 create.ivar
  75. ;
  76.  
  77. : IV.BYTE  ( <name> --IN-- , declare a byte wide instance variable )
  78.     -1 create.ivar
  79. ;
  80.  
  81. : IV.UBYTE  ( <name> --IN-- , declare a byte wide instance variable )
  82.     1 create.ivar
  83. ;
  84.  
  85. : IV=>  ( value <ivar> -- , store into ivar )
  86.     ?COMP
  87.     compile os.copy
  88.     ob.stats? compile+!bytes
  89. ; immediate
  90.  
  91. : IV+>  ( value <ivar> -- , add value to ivar )
  92.     ?COMP
  93.     ob.stats? cell =
  94.     IF [compile] literal compile iv+!
  95.     ELSE " IV+>" " only works on IV.LONG !!"
  96.         er_fatal er.report
  97.     THEN
  98. ; immediate
  99.  
  100. : IV&   ( offset -- address_ivar )
  101.     os+
  102. ;
  103.  
  104. : IV&>  ( <ivar> --IN-- address_ivar , calculate address of ivar )
  105.     ?COMP
  106.     ob.findit ob.offset@ [compile] literal compile os+
  107. ; immediate
  108.  
  109. \ This is for declaring a field of bytes in an object.
  110. : IV.BYTES ( n <name> -- , declare a field of bytes )
  111.     CREATE ob.make.member immediate
  112.     DOES> ?comp @ [compile] literal compile os+
  113. ;
  114.  
  115. : IV.STRUCT ( <structure> <name> -- ) ( -- addr )
  116.     [compile] sizeof() iv.bytes
  117. ;
  118.